package com.yanqu.road.server.cmd.activity;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.pb.activity.ActivityProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/10/29 0:40
 */
@Cmd(code = GameProtocol.S_EXPRESSION_ACTIVITY_CHOOSE, desc = "表情包活动选择")
public class ExpressionActivityChooseCmd extends AbstractCommand {
    private int activityId;
    private int choose;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ActivityProto.ExpressionActivityChooseReqMsg msg = ActivityProto.ExpressionActivityChooseReqMsg.parseFrom(packet.getBytes());
        activityId = msg.getActivityId();
        choose = msg.getChoose();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ActivityInfo activityInfo = NormalActivityMgr.getActivityInfo(activityId);
        if (activityInfo == null) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
        }
        String paramStr = activityId + ";" + choose;
        player.notifyListener(eGamePlayerEventType.ExpressionActivityChoose.getValue(), paramStr);
    }

    @Override
    public void sendData(GamePlayer player) {
        ActivityProto.ExpressionActivityChooseRespMsg.Builder respMsg = ActivityProto.ExpressionActivityChooseRespMsg.newBuilder();
        respMsg.setRet(ret);
        player.sendPacket(ClientProtocol.S_EXPRESSION_ACTIVITY_CHOOSE, respMsg);
    }
}
